package com.origin.baselibrary.expand

import android.os.SystemClock
import androidx.lifecycle.MutableLiveData

public class MutableListLiveData<E> : ArrayList<E>() {
    var mutableListState: MutableLiveData<Long> = MutableLiveData()
//    Collection<? extends E> c
    //清除并重新添加


    fun clearAndAll(c: kotlin.collections.Collection<E>) {
        clear()
        addAll(c)
        mutableListState.postValue(SystemClock.elapsedRealtime())
    }

    fun add(c: kotlin.collections.Collection<E>) {
        addAll(c)
        mutableListState.postValue(SystemClock.elapsedRealtime())
    }

    fun addItem(c: E) {
        add(c)
        mutableListState.postValue(SystemClock.elapsedRealtime())
    }
    fun clearSendMsg(){
        clear()
        refreshMsg()
    }

    override fun add(element: E): Boolean {
        val result = super.add(element)
        mutableListState.postValue(SystemClock.elapsedRealtime())
        return result
    }

    override fun remove(element: E): Boolean {
        val result = super.remove(element)
        mutableListState.postValue(SystemClock.elapsedRealtime())
        return result
    }

    fun refreshMsg() {
        mutableListState.postValue(SystemClock.elapsedRealtime())
    }
}